package com.mdd.front.controller;

import com.mdd.common.constant.GlobalConstant;
import com.mdd.common.core.PageResult;
import com.mdd.common.utils.ConfigUtil;
import com.mdd.front.service.time.IOrderTimeService;
import com.mdd.front.validate.PageParam;
import com.mdd.front.vo.time.OrderTimeListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 订单预约时间管理
 */
@Api(tags = "订单预约时间管理")
@RestController
@RequestMapping("api/time")
public class OrderTimeController {

    @Resource
    IOrderTimeService iOrderTimeService;

    /**
     * 订单预约时间列表
     *
     * @param pageParam 分页参数
     * @param params    搜索参数
     * @return Object
     */
    @ApiOperation(value = "订单预约时间管理 - 时间列表")
    @GetMapping("/list")
    public PageResult<OrderTimeListVo> list(@Validated PageParam pageParam,
                                            @RequestParam Map<String, String> params) {
        return iOrderTimeService.list(pageParam, params);
    }

    /**
     * 获取可提前预约时间
     *
     * @return Object
     */
    @ApiOperation(value = "订单预约时间管理 - 获取提前预约时长")
    @GetMapping("/getTime")
    public int getTime() {
        return Integer.parseInt(ConfigUtil.get(GlobalConstant.ORDER_TIME_TYPE, GlobalConstant.ORDER_TIME));
    }

}
